<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="utf-8">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
    <div id="example">
        <p>Original message: "{{ message }}"</p>
        <p>Computed reversed message: "{{ reversedMessage }}"</p>
        <p>now:{{now}}</p>
    </div>
    <div id="demo">{{ fullName }}</div>
    <script type="text/javascript">
        var vm = new Vue({
            el: '#example',
            data: {
                message: 'Hello'
            },
            computed: {
                // 计算属性的 getter
                reversedMessage: function () {
                    // `this` 指向 vm 实例
                    return this.message.split('').reverse().join('')
                },
                now: function () {
                    return Date.now()
                }
            }
        });
        var vm = new Vue({
            el: '#demo',
            data: {
                firstName: 'Foo',
                lastName: 'Bar',
                fullName: 'Foo Bar'

            },
            computed: {
                 fullName: function () {
                     return this.firstName + ' ' + this.lastName
                 }
             }
             

            // computed: {
            //     fullName: {
            //         // getter
            //         get: function () {
            //             return this.firstName + ' ' + this.lastName
            //         },
            //         // setter
            //         set: function (newValue) {
            //             var names = newValue.split(' ')
            //             this.firstName = names[0]
            //             this.lastName = names[names.length - 1]
            //         }
            //     }
            // }
        });
        // vm.fullName = 'John Doe'
    </script>
</body>

</html>